package com.youhome.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.youhome.mapper.NewsMapper;
import com.youhome.model.News;
import com.youhome.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.xml.ws.Action;
import java.util.List;

/**
 * Created by chen365 on 2018/12/10.
 */
@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsMapper newsMapper;

    @Override
    public News selectByPrimaryKey(Long id) {
        return newsMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<News> selectByBean(Integer pageNumber, Integer pageSize, News record) {
        if (StringUtils.isEmpty(pageNumber) || pageNumber < 1) {
            pageNumber = 1;
        }
        if (StringUtils.isEmpty(pageSize) || pageSize < 1) {
            pageSize = 10;
        }
        PageHelper.startPage(pageNumber, pageSize);
        List<News> news = newsMapper.selectByBean(record);
        return new PageInfo<>(news);
    }
}
